﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QRCode.Models;

namespace QRCode.Controllers
{
    public class HomeForSaleController : Controller
    {
        private HomeQRCodeDBContext db = new HomeQRCodeDBContext();

        //
        // GET: /HomeForSale/

        [Authorize(Roles = "RealEstateAgent")]
        public ActionResult Index()
        {
            return View(db.HomeForSales.ToList());
        }

        //
        // GET: /HomeForSale/Details/5

        [Authorize(Roles = "RealEstateAgent")]
        public ActionResult Details(int id = 0)
        {
            HomeForSale homeforsale = db.HomeForSales.Find(id);
            if (homeforsale == null)
            {
                return HttpNotFound();
            }
            return View(homeforsale);
        }

        //
        // GET: /HomeForSale/Create

        [Authorize(Roles = "RealEstateAgent")]
        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /HomeForSale/Create

        [HttpPost]
        [Authorize(Roles = "RealEstateAgent")]
        //[ValidateAntiForgeryToken]
        public ActionResult Create(HomeForSale homeforsale, HttpPostedFileBase MainPicture, HttpPostedFileBase Picture1, HttpPostedFileBase Picture2, HttpPostedFileBase Picture3, HttpPostedFileBase Picture4, HttpPostedFileBase Picture5)
        {
            if (ModelState.IsValid)
            {
                db.HomeForSales.Add(homeforsale);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(homeforsale);
        }

        //
        // GET: /HomeForSale/Edit/5

        public ActionResult Edit(int id = 0)
        {
            HomeForSale homeforsale = db.HomeForSales.Find(id);
            if (homeforsale == null)
            {
                return HttpNotFound();
            }
            return View(homeforsale);
        }

        //
        // POST: /HomeForSale/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(HomeForSale homeforsale)
        {
            if (ModelState.IsValid)
            {
                db.Entry(homeforsale).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(homeforsale);
        }

        //
        // GET: /HomeForSale/Delete/5

        public ActionResult Delete(int id = 0)
        {
            HomeForSale homeforsale = db.HomeForSales.Find(id);
            if (homeforsale == null)
            {
                return HttpNotFound();
            }
            return View(homeforsale);
        }

        //
        // POST: /HomeForSale/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            HomeForSale homeforsale = db.HomeForSales.Find(id);
            db.HomeForSales.Remove(homeforsale);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}